package com.desmart.ht;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ScheduleDetailActivity extends BaseActivity implements View.OnClickListener {

    public static final String Key_Type = "Key_Type";
    public static final int type_watch = 0;
    public static final int type_edit = 1;
    private TextView tvCancel;
    private TextView tvSumbit;
    private int mType;
    private View tvTypeContent;
    private View tvCategoryContent;
    private View tvStartTimeContent;
    private View tvEndTimeContent;

    public static void start(Context context,int type){
        Intent intent = new Intent(context,ScheduleDetailActivity.class);
        intent.putExtra(Key_Type,type);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_schedule_detail);
        mType = getIntent().getIntExtra(Key_Type, type_watch);
        initTitle();
        initViews();
    }

    private void initViews() {
        //类型
        View typeView = findViewById(R.id.view_type);
        TextView tvTypeTitle = typeView.findViewById(R.id.tv_item_title);
        tvTypeContent = typeView.findViewById(R.id.tv_item_content);
        tvTypeContent.setOnClickListener(this);
        tvTypeTitle.setText("类型");

        //类别
        View categoryView = findViewById(R.id.view_category);
        TextView tvCategoryTitle = categoryView.findViewById(R.id.tv_item_title);
        tvCategoryContent = categoryView.findViewById(R.id.tv_item_content);
        tvCategoryContent.setOnClickListener(this);
        tvCategoryTitle.setText("类别");

        //标题
        View InputTitleView = findViewById(R.id.view_input_title);
        EditText etTitle = InputTitleView.findViewById(R.id.et_item_input);
        etTitle.setHint("请输入标题");

        //描述
        View InputDescribeView = findViewById(R.id.view_input_describe);
        EditText etDescribe = InputDescribeView.findViewById(R.id.et_item_input);
        etDescribe.setHint("请输入描述");

        //来源
        View fromView = findViewById(R.id.view_from);
        TextView tvFromTitle = fromView.findViewById(R.id.tv_item_title);
        TextView tvFromContent = fromView.findViewById(R.id.tv_item_content);
        tvFromTitle.setText("来源");

        //状态
        View statusView = findViewById(R.id.view_status);
        TextView tvStatusTitle = statusView.findViewById(R.id.tv_item_title);
        TextView tvStatusContent = statusView.findViewById(R.id.tv_item_content);
        tvStatusTitle.setText("状态");

        //开始时间
        View startTimeView = findViewById(R.id.view_start_time);
        TextView tvStartTimeTitle = startTimeView.findViewById(R.id.tv_item_title);
        tvStartTimeContent = startTimeView.findViewById(R.id.tv_item_content);
        tvStartTimeContent.setOnClickListener(this);
        tvStartTimeTitle.setText("开始时间");

        //结束时间
        View endTimeView = findViewById(R.id.view_end_time);
        TextView tvEndTimeTitle = endTimeView.findViewById(R.id.tv_item_title);
        tvEndTimeContent = endTimeView.findViewById(R.id.tv_item_content);
        tvEndTimeContent.setOnClickListener(this);
        tvEndTimeTitle.setText("结束时间");

        //接收人
        View receiveView = findViewById(R.id.view_receive);
        TextView tvReceiveTitle = receiveView.findViewById(R.id.tv_item_title);
        tvReceiveTitle.setText("接收人");

        //提醒
        View remindView = findViewById(R.id.view_remind);
        TextView tvRemindTitle = remindView.findViewById(R.id.tv_item_title);
        tvRemindTitle.setText("提醒");

        //附件上传
        View attachmentView = findViewById(R.id.view_attachment);
        TextView tvAttachmentTitle = attachmentView.findViewById(R.id.tv_item_title);
        tvAttachmentTitle.setText("附件上传");

        //反馈记录
        View feekBackView = findViewById(R.id.view_feedback);
        TextView tvFeekBackTitle = feekBackView.findViewById(R.id.tv_item_title);
        tvFeekBackTitle.setText("反馈记录");

        //地址
        View addressInputView = findViewById(R.id.view_input_address);
        EditText etAddress = addressInputView.findViewById(R.id.et_item_input);
        etAddress.setHint("请输入地址");

        //按钮
        Button btnLeft = findViewById(R.id.btn_left);
        Button btnRight = findViewById(R.id.btn_right);
        btnLeft.setOnClickListener(this);
        btnRight.setOnClickListener(this);

        if (mType == type_edit){
            btnRight.setVisibility(View.GONE);
            btnLeft.setText("删除");
        }

    }

    private void initTitle() {
        tvCancel = findViewById(R.id.tv_title_left);
        tvSumbit = findViewById(R.id.tv_title_right);
        TextView tvTitle = findViewById(R.id.tv_title);
        if (mType == type_watch){
            tvSumbit.setText("编辑");
            tvTitle.setText("查看日程");
        } else if (mType == type_edit){
            tvSumbit.setText("保存");
            tvTitle.setText("编辑日程");
        }
        tvCancel.setOnClickListener(this);
        tvSumbit.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        if (view == tvCancel){
            onBackPressed();
        }else if (view == tvSumbit){
            ScheduleDetailActivity.start(this,type_edit);
        }

    }
}
